# -*- coding: utf-8 -*-
# @Time    : 2023/6/5 11:24
# @Author  : lxy
# @Email   : 1612393119@qq.com
# @File    : course_details_page.py
# @Software: PyCharm
from pages.base_page import BasePage
from appium.webdriver.common.mobileby import MobileBy as By

class CourseDetailPage(BasePage):
    course_neirong_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().className(\"android.view.View\")')
    collect_course_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().className(\"android.view.View\")')
    # collected_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().className(\"android.view.View\")')
    # collected_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().descriptionContains("已收藏")')
    collected_locator = (By.ANDROID_VIEW_MATCHER,'android.view.View')
    author_head_locator=(By.XPATH,'//android.view.View[@content-desc="面少Sansan"]')
    back_locator=(By.XPATH,'//*[@content-desc="返回"]')
    money_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().className(\"android.view.View\")')

    # 获取课程详情页文本
    def course_detail(self):
        detail=self.find_element(self.course_neirong_locator).get_attribute('name')
        return detail
    # 点击收藏课程
    def collect_course(self):
        self.find_element(self.collect_course_locator).click()
    # 获取收藏之后图标的文本
    def collected_course(self,attr):
        # collected=self.find_element(self.collected_locator).get_attribute(attr)

        # return collected
        views = self.driver.find_elements(self.collected_locator)
        print("view个数=",len(views))
        print("index内容---",views[-3].get_attribute("index"))
        print("content-desc内容---", views[-3].get_attribute("content-desc"))

    def author_head(self):
        self.find_element(self.author_head_locator).click()

    #返回课堂页面
    def back_course(self):
        self.find_element(self.back_locator).click()

    #点击课程金额购买
    def money_course(self):
        self.find_element(self.money_locator).click()
